﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using White.WebBrowser.Silverlight;

namespace SilverlightLesson1
{
    public abstract class BaseLibrary
    {
        /// <summary>
        /// Method to get control from silverlight document
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="strControlName"></param>
        /// <param name="document"></param>
        /// <returns></returns>
        public static T GetControl<T>(String strControlName,SilverlightDocument document) where T : class
        {
            if (document == null) throw new Exception("No test in progress");
            if (String.IsNullOrEmpty(strControlName)) throw new Exception("Control name is required. Please specify");
            T control = document.Get(White.Core.UIItems.Finders.SearchCriteria.ByText(strControlName)) as T;
            if (control == null) control = document.Get(White.Core.UIItems.Finders.SearchCriteria.ByAutomationId(strControlName)) as T;
            if (control == null) throw new Exception(string.Format("No Such {0} control by name {1} ",typeof(T).Name,strControlName));
            return control;
        }
    }
}
